<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>登录</title>
    <link rel="stylesheet" href="/static/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/admin-login.css">
</head>
<body>
<div class="login-main">
    <div class="container">
        <div class="warp-login">
            <div class="logo-title layui-anim layui-anim-scale">
                CodeLog
            </div>
            <form class="layui-form layui-anim layui-anim-scale">
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input class="layui-input" type="text" name="username" lay-verify="required"
                               placeholder="CodeLog" autocomplete="off">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input class="layui-input" type="password" name="userpass" lay-verify="required"
                               placeholder="******" autocomplete="off">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block layui-anim-up form-btn">
                        <button class="layui-btn" lay-submit lay-filter="login">立即登录</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>


<script src="/static/lib/layui/layui.js"></script>
<script src="/static/js/jquery/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
    layui.use('form', function () {
        var form = layui.form;

        //监听提交
        form.on('submit(login)', function (data) {
            var loginBtn = $(this);
            loginBtn.addClass("layui-btn-disabled");
            loginBtn.text("登录中...");
            $.ajax({
                url: "/admin/doLogin",
                type: "post",
                dataType: "json",
                data: {
                    userName: data.form.username.value,
                    userPass: data.form.userpass.value
                },
                success: function (result) {
                    if (result.code === 2001) {
                        layer.msg(result.message, {
                            icon: 1, time: 1000
                        }, function () {
                            window.location.href = "/admin/index";
                        });
                    } else {
                        layer.msg(result.message, {
                            icon: 5, time: 1000
                        }, function () {
                            loginBtn.removeClass("layui-btn-disabled");
                            loginBtn.text("立即登录");
                        });
                    }
                }, error: function () {
                    layer.msg("登录失败", {
                        icon: 6, time: 1000
                    }, function () {
                        loginBtn.removeClass("layui-btn-disabled");
                        loginBtn.text("立即登录");
                    });
                }
            });
            return false;
        });
    });
</script>
</body>
</html>